clear all

***************************************************************************
* Panel A
***************************************************************************

use "nlsy_pseudo", clear
gen es_group = .
replace es_group = 1 if es_pct >= 0 & es_pct < 0.33
replace es_group = 2 if es_pct >= 0.33 & es_pct < 0.66
replace es_group = 3 if es_pct >= 0.66 & es_pct <= 1
collapse fin_distress, by(es_group)

replace fin_distress = fin_distress*100

generate str cat = "Low" in 1
replace cat = "Medium" in 2
replace cat = "High" in 3

graph bar fin_distress, over(cat, sort(es_group) label(labsize(vsmall)) gap(*1.5)) ytitle("Payment difficulties (in %)", size(small) color(black)) exclude0 ylabel(0(5)20, labsize(vsmall) labcolor(black) tlcolor(black) nogrid) ymtick(0(5)20) graphregion(color(white)) bar(1, color(black)) blabel(bar,position(outside) format(%9.1f) size(vsmall)) outergap(75)

local nb=`.Graph.plotregion1.barlabels.arrnels'
forval i=1/`nb' {
  di "`.Graph.plotregion1.barlabels[`i'].text[1]'"
  .Graph.plotregion1.barlabels[`i'].text[1]="`.Graph.plotregion1.barlabels[`i'].text[1]'%"
}
.Graph.drawgraph

***************************************************************************
* Panel B
***************************************************************************

use "hrs_pseudo", clear
gen es_group = .
replace es_group = 1 if es_pct >= 0 & es_pct < 0.33
replace es_group = 2 if es_pct >= 0.33 & es_pct < 0.66
replace es_group = 3 if es_pct >= 0.66 & es_pct <= 1
collapse fin_distress, by(es_group)

replace fin_distress = fin_distress*100

generate str cat = "Low" in 1
replace cat = "Medium" in 2
replace cat = "High" in 3

graph bar fin_distress, over(cat, sort(es_group) label(labsize(vsmall)) gap(*1.5)) ytitle("Payment difficulties (in %)", size(small) color(black)) exclude0 ylabel(0(5)20, labsize(vsmall) labcolor(black) tlcolor(black) nogrid) ymtick(0(5)20) graphregion(color(white)) bar(1, color(black)) blabel(bar,position(outside) format(%9.1f) size(vsmall)) outergap(75)

local nb=`.Graph.plotregion1.barlabels.arrnels'
forval i=1/`nb' {
  di "`.Graph.plotregion1.barlabels[`i'].text[1]'"
  .Graph.plotregion1.barlabels[`i'].text[1]="`.Graph.plotregion1.barlabels[`i'].text[1]'%"
}
.Graph.drawgraph

***************************************************************************
* Panel C
***************************************************************************

use "hilda_pseudo", clear
gen es_group = .
replace es_group = 1 if es_pct >= 0 & es_pct < 0.33
replace es_group = 2 if es_pct >= 0.33 & es_pct < 0.66
replace es_group = 3 if es_pct >= 0.66 & es_pct <= 1
collapse late_house, by(es_group)

replace late_house = late_house*100

generate str cat = "Low" in 1
replace cat = "Medium" in 2
replace cat = "High" in 3

graph bar late_house, over(cat, sort(es_group) label(labsize(vsmall)) gap(*1.5)) ytitle("Housing PD (in %)", size(small) color(black)) exclude0 ylabel(0(5)20, labsize(vsmall) labcolor(black) tlcolor(black) nogrid) ymtick(0(5)20) graphregion(color(white)) bar(1, color(black)) blabel(bar,position(outside) format(%9.1f) size(vsmall)) outergap(75)

local nb=`.Graph.plotregion1.barlabels.arrnels'
forval i=1/`nb' {
  di "`.Graph.plotregion1.barlabels[`i'].text[1]'"
  .Graph.plotregion1.barlabels[`i'].text[1]="`.Graph.plotregion1.barlabels[`i'].text[1]'%"
}
.Graph.drawgraph

***************************************************************************
* Panel D
***************************************************************************

use "hilda_pseudo", clear
gen es_group = .
replace es_group = 1 if es_pct >= 0 & es_pct < 0.33
replace es_group = 2 if es_pct >= 0.33 & es_pct < 0.66
replace es_group = 3 if es_pct >= 0.66 & es_pct <= 1
collapse late_bills, by(es_group)

replace late_bills = late_bills*100

generate str cat = "Low" in 1
replace cat = "Medium" in 2
replace cat = "High" in 3

graph bar late_bills, over(cat, sort(es_group) label(labsize(vsmall)) gap(*1.5)) ytitle("Utility PD (in %)", size(small) color(black)) exclude0 ylabel(0(5)20, labsize(vsmall) labcolor(black) tlcolor(black) nogrid) ymtick(0(5)20) graphregion(color(white)) bar(1, color(black)) blabel(bar,position(outside) format(%9.1f) size(vsmall)) outergap(75)

local nb=`.Graph.plotregion1.barlabels.arrnels'
forval i=1/`nb' {
  di "`.Graph.plotregion1.barlabels[`i'].text[1]'"
  .Graph.plotregion1.barlabels[`i'].text[1]="`.Graph.plotregion1.barlabels[`i'].text[1]'%"
}
.Graph.drawgraph
